home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_03 / allison / mathdemo.c < prev    next >
C/C++ Source or Header  |  1995-01-03  |  756b  |  32 lines

  1. LISTING 4 - Illustrates several <math.h> functions
  2.  
  3. #include <stdio.h>
  4. #include <math.h>
  5.  
  6. main()
  7. {
  8.     double x = 1234.56, y = 90.1234, z, w;
  9.     int p;
  10.  
  11.     printf("x == %g, y == %g\n",x,y);
  12.     printf("fmod(x,y) == %g\n",fmod(x,y));
  13.     printf("floor(y) == %g\n",floor(y));
  14.     printf("ceil(y) == %g\n",ceil(y));
  15.     w = modf(y,&z);
  16.     printf("after modf(y,&z): w == %g, z == %g\n",w,z);
  17.     w = frexp(y,&p);
  18.     printf("after frexp(y,&p): w == %g, p == %d\n",w,p);
  19.     printf("ldexp(w,p) == %g\n",ldexp(w,p));
  20.     return 0;
  21. }
  22.  
  23. /* Output:
  24. x == 1234.56, y == 90.1234
  25. fmod(x,y) == 62.9558
  26. floor(y) == 90
  27. ceil(y) == 91
  28. after modf(y,&z): w == 0.1234, z == 90
  29. after frexp(y,&p): w == 0.704089, p == 7
  30. ldexp(w,p) == 90.1234
  31. */
  32.